package com.example.myapplication

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Email
import androidx.compose.material.icons.filled.Phone
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            MyApplicationTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    GreetingImage(
                        name = "Android",
                        name2 = "XL",
                        modifier = Modifier.padding(innerPadding)
                    )
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, name2: String, modifier: Modifier = Modifier) {
    Column(
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = modifier.padding(4.dp)
    ) {
        Text(
            text = "$name",
            fontSize = 100.sp,
            lineHeight = 80.sp,
            textAlign = TextAlign.Center,
            color = Color.Yellow
        )

        // 在文字中间插入圆形照片
        Image(
            painter = painterResource(R.drawable.wect2), // 使用你的图片资源
            contentDescription = "中间图片",
            modifier = Modifier
                .size(150.dp) // 设置图片大小，可以调整这个值
                .clip(CircleShape) // 将图片裁剪为圆形
                .padding(16.dp), // 添加一些内边距
            contentScale = ContentScale.Crop // 图片缩放方式
        )

        Text(
            text = "from $name2",
            fontSize = 30.sp,
            lineHeight = 26.sp,
            modifier = Modifier.padding(16.dp),
            color = Color.Green
        )

        // 添加邮箱信息（带图标）
        Row(
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.Center,
            modifier = Modifier.padding(8.dp)
        ) {
            Icon(
                imageVector = Icons.Default.Email,
                contentDescription = "邮箱图标",
                tint = Color.White,
                modifier = Modifier.size(2.dp)
            )
            Spacer(modifier = Modifier.width(8.dp))
            Text(
                text = "483782836@qq.com",
                fontSize = 20.sp,
                color = Color.White
            )
        }

        // 添加电话信息（带图标）
        Row(
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.Center,
            modifier = Modifier.padding(8.dp)
        ) {
            Icon(
                imageVector = Icons.Default.Phone,
                contentDescription = "电话图标",
                tint = Color.White,
                modifier = Modifier.size(20.dp)
            )
            Spacer(modifier = Modifier.width(1.dp))
            Text(
                text = "4455787",
                fontSize = 20.sp,
                color = Color.White
            )
        }
    }
}

@Composable
fun GreetingImage(name: String, name2: String, modifier: Modifier = Modifier) {
    val image = painterResource(R.drawable.wect3)
    Box(modifier = modifier.fillMaxSize()) {
        Image(
            painter = image,
            contentDescription = "背景图片",
            modifier = Modifier.fillMaxSize(),
            contentScale = ContentScale.Crop
        )
        Greeting(
            name = name,
            name2 = name2,
            modifier = Modifier.fillMaxSize()
        )
    }
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    MyApplicationTheme {
        GreetingImage("My ID card", "XL")
    }
}